<?php
	require_once 'header.php';
	require_once 'navigation.php';
	//productid
	if (isset($_GET['pid'])) 
	{
		$pid = $_GET['pid'];
	}
	else 
	{
		$pid = $_POST['pid'];
	}
	
	if($pid!=null)
	{
	    //left content
		$columns = $adminDB->executeSQL("select id, fdName from ".$util->contentdbName().".tbColumn order by fdOrder", $connID);	
		$smarty->assign('columns', $columns);
		//content list
		$contents = $adminDB->executeSQL("select i.fdColumnID as ColumnID, p.fdName as ContentName, p.id as ProductID from ".$util->contentdbName().".tbIndex i left outer join ".$util->contentdbName().".tbProduct p on p.fdContentID = i.fdContentID where p.fdStatus != 3 order by p.id", $connID);	
		$smarty->assign('contents', $contents);	
		//column of selected product
		$activecolumn = $adminDB->executeSQL("select fdColumnID from ".$util->contentdbName().".tbIndex i left outer join ".$util->contentdbName().".tbProduct p on i.fdContentID = p.fdContentID where p.id = ".$pid."", $connID);	
		$smarty->assign('activecolumn', $activecolumn);

		$smarty->display('content_left.html');	
		//right content
		$product = $adminDB->executeSQL("select id, fdName,fdTarget,fdListPrice,fdPrice,fdDescription,fdMemo,fdVersion,fdLicense,fdStatus from ".$util->contentdbName().".tbProduct where id = ".$pid."", $connID);
		$smarty->assign('product', $product);		
		//related products by license or version
		$license = $adminDB->executeSQL("select r.fdRelateID, p.fdLicense from ".$util->contentdbName().".tbRelate r left outer join ".$util->contentdbName().".tbProduct p on r.fdRelateID = p.id where r.fdProductID = ".$pid." and r.fdTypeID = 2", $connID);
		$smarty->assign('license', $license);
		$version = $adminDB->executeSQL("select r.fdRelateID, p.fdVersion from ".$util->contentdbName().".tbRelate r left outer join ".$util->contentdbName().".tbProduct p on r.fdRelateID = p.id where r.fdProductID = ".$pid." and r.fdTypeID = 1", $connID);
		$smarty->assign('version', $version);
		//product pictures
		$pictures = $adminDB->executeSQL("select f.fdURL as FileURL from ".$util->contentdbName().".tbProduct p left outer join ".$util->contentdbName().".tbFile f on f.fdContentID = p.fdContentID where p.id = ".$pid." order by f.fdUpdated", $connID);	
		$smarty->assign('pictures', $pictures);
		
		$smarty->display('content_right.html');
		
		//validate login
		if (isset($_SESSION['unc']) && $_SESSION['unc'] != '') {
			$smarty->assign('isLogin', 'T');
		} else {
			$smarty->assign('isLogin', 'F');
			if (isset($_SESSION['toUrl'])) {
				unset($_SESSION['toUrl']);
			}
			$_SESSION['toUrl'] = 'details.php?pid='.$pid.'';
		}
	}
	
	require_once 'footer.php';
?>